import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

MAGIC = np.uint32(0x15432345)
UINT_32_SIZE = 4
UINT_8_SIZE = 1

def load_map(addr):
    file = open(addr, "rb")
    my_magic = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=False)
    if my_magic != MAGIC:
        return -1
    mx = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    my = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    _map = [[] for i in range(mx)]
    for i in range(0, mx * my):
        k = int(i / mx)
        _map[k].append(int.from_bytes(file.read(UINT_8_SIZE), byteorder='little', signed=True))
    m_start_x = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    m_start_y = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    m_end_x = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    m_end_y = int.from_bytes(file.read(UINT_32_SIZE), byteorder='little', signed=True)
    print(m_start_x,m_start_y,m_end_x,m_end_y)
    file.close()
    return _map

fig = plt.figure()
sns_plot = sns.heatmap(load_map("test_7.map"), cmap="Greys")
plt.show()
fig = plt.figure()
sns_plot = sns.heatmap(load_map("test_1.map"), cmap="Greys")
plt.show()


